from pprint import pprint
from DrissionPage import Chromium
from threading import Thread
import time
from CDPClient import WebSocketCDPClient, CDP

def startJsonListener(tab): 
    # 初始化 WebSocket 客户端
    ws_client = WebSocketCDPClient(tab, debug=True)
    # 设置响应接收监听器
    ws_client.set_listener(CDP.Network.responseReceived, ws_client.received_data_and_save(type='json'))
    # 获取所有的数据包列表


port=9522
b=Chromium(port)  # ws://localhost:9522/devtools/page/


tab=b.latest_tab
startJsonListener(tab)


# 设置目标 URL 并打开
target_url = 'https://wxhzhwxhzh.github.io/saossion_code_helper_online/'
target_url = 'https://spa1.scrape.center/'
target_url = 'https://ai.gitcode.com/models'
target_url = 'https://xiaohongshu.com'
target_url = 'https://cn.bing.com/'

tab.get(target_url)
# tab.wait(9)






input("请按回车键继续")    